package com.sl.au.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.EXDELoginInfo;
import com.sl.au.entity.User;

import java.util.List;

public interface UserRepository extends JpaRepository<User, String> {
	@Query("select u from User u where (u not in(select a.user from Account a )) and (u.disable=1)")
	List<User> findAccountIsNull();

	@Query("select u from User u where u.disable=0 and " + "(u.empLogin.name like '%'+?1+'%' " + "or u.sex like '%'+?1+'%'  "
			+ "or u.saleArea.superior like '%'+?1+'%'  " + "or u.saleArea.areaName like '%'+?1+'%')  "
			+ "or u.position like '%'+?1+'%' ")
	Page<User> getUserName(String key, Pageable pageable);

	@Query("select u from User u where u.empId=?1 and u.disable=0")
	User getByEmpId(String empId);

	@Query("select u from User u where u.id " + "  not in( select a.user.id from Account a ) and (u.disable=0)")
	List<User> getNoAccount();
	
	
	/*
	 * 获得本部门的用户
	 */
	@Query("select u from User u where u.saleArea.superior=?1 and u.disable=0")
	List<User> getBySuperior(String superior);

	User findByEmpId(String empId);

	@Query("select u from User u where u.empLogin.name=?1 and u.disable=0 order by u.createTime asc")
	List<User> findByEmpName(String name);
}
